package com.fengwk.resource.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fengwk.resource.dao.ResPageDao;
import com.fengwk.resource.face.entity.ResPage;
import com.fengwk.resource.service.PageService;
import com.fengwk.support.cache.CacheMap;
import com.fengwk.support.exception.BaseException;
import com.fengwk.support.util.CacheUtils;

@Service
public class PageServiceImpl implements PageService {

	private static final long CACHE_TIMEOUT = 1000 * 60;
	
	private static final CacheMap<String, String> CACHE = CacheUtils.map(CACHE_TIMEOUT);
	
	@Autowired
	private ResPageDao rpDao;
	
	@Override
	public String getUrlByName(String name) {
		String url = CACHE.get(name);
		if (url == null) {
			ResPage rp = rpDao.findByName(name);
			if (rp == null)
				throw new BaseException("页面名称不存在");
			
			url = rp.getUrl();
			CACHE.put(name, url);
		}
		return url;
	}
	
}
